#ifndef SERIAL_PORT_H
#define SERIAL_PORT_H

#include <QThread>
#include <QDebug>
#include <QFile>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>

#include "user/my_protocol.h"
#include "user/circle_queue.h"


class Serial_Port : public QObject
{
    Q_OBJECT
public:
    Serial_Port(QString port_name, int baudrate);
    ~Serial_Port();

    Circle_queue *serial_port_tx_queue;
    Circle_queue *serial_port_rx_queue;

    bool open_serial_port(QString port_name, int baudrate);   //打开串口
    bool close_serial_port(void);
    void write_serial_port(char *p_data,int len);               //写串口数据

public slots:
    void slot_write_serial_port(char *p_data,int len);               //写串口数据
    void slot_byteswriten_serial_port(qint64 bytes);

signals:
    void read_serial_signals();
    void signal_byteswritten(qint64 bytes);
private slots:
    int slot_read_serial_port();       //read serial port data


private:

    QSerialPort *serial_port;    //定义一个串口对象

};

#endif


